package demo.Thread;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/10-08-10-18:38
 * @Description：demo.Thread
 */
/*
现在有T1、T2、T3三个线程，怎样保证T2在T1执行完后执行，T3在T2执行完后执行
 */
public class threeThread_run {
    public static void main(String[] args) {
        Thread thread1 = new Thread(){
            @Override
            public void run() {
                System.out.println("thread1: threeThread_run.run");
            }
        };
        Thread thread2 = new Thread(){
            @Override
            public void run() {
                try {
                    thread1.join();              //保证T2在T1执行完后执行，
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("thread2: threeThread_run.run");
            }
        };
        Thread thread3 = new Thread(){
            @Override
            public void run() {
                try {
                    thread2.join();         //保证T3在T2执行完后执行
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("thread3: threeThread_run.run");
            }
        };
        thread1.start();
        thread2.start();
        thread3.start();
    }
}
